<?php
namespace Setting\Controller;

use Base\Controller\AdminBaseController;

class SettingController extends AdminBaseController{
	
	protected $settingModel;
	
	public function _initialize() {
		parent::_initialize();
		
		$this->settingModel = D("Setting/Setting");
	}
	
	/******************************** JSON *********************************/
	/** 添加信息 */
	public function saveOne() {
		$settingJson = file_get_contents('php://input');
		$setting = json_decode($settingJson, true);

		M()->execute("TRUNCATE __SETTING__");
		$result = $this->settingModel->add($setting);
		if (!$result) {
			$data['code'] = 499;
			$data['msg'] = '编辑失败！';
			$this->ajaxReturn($data);
		}

		$newSetting = $this->settingModel->find();
			
		$data['code'] = 0;
		$data['msg'] = '编辑成功！';
		$data['obj'] = $newSetting;
		$this->ajaxReturn($data);
	}
	
	/** 查看某信息 */
	public function findOne() {
// 		$id = $_GET['id'];
// 		$setting = $this->settingModel->where(array("id" => $id))->find();
		$setting = $this->settingModel->find();
	    $data['code'] = 0;
	    $data['msg'] = 'OK';
	    $data['obj'] = $setting;
	    $this->ajaxReturn($data);
	}
	

	/******************************** HTML *********************************/
	/** index */
    public function index() {
		$this->display(':setting');
		return;
	}
	
	/** 清除缓存 */
	public function clearCache(){
		clearCache();

		$data['code']  = 0;
		$data['msg'] = '清除缓存完成！';
		$this->ajaxReturn($data);
	}
	
	
}